﻿using System;
// to set up custom bindings for Azure access
using System.Windows;
using System.ComponentModel;
using MyFloridaHouse.libSvUtilities.Logging;

namespace MyFloridaHouse.libSvOpenDistricts.DataService
{
    public partial class ServiceDAL : INotifyPropertyChanged
    {
        #region INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion

		// Todo: figure out how to make this a configruation value rather than hard coded.
		private string _relativeBindingName = "BasicHttpBindingRelativeBinding";	// The name of the binding in the ServiceReference.ClientConfig file.

		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="ServiceDAL"/> class.
		/// Uses a default binding name: BasicHttpBindingRelativeBinding
		/// </summary>
		public ServiceDAL()
		{
			
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="ServiceDAL"/> class. This passes the name
		/// of the WCF binding endpoint that is in the silverlight application's ServiceReferences.ClientConfig file.
		/// </summary>
		/// <param name="relativeBindingName">Name of the relative binding.</param>
		public ServiceDAL(string relativeBindingName)
		{
			if (!String.IsNullOrEmpty(relativeBindingName))
				_relativeBindingName = relativeBindingName;
		}
		#endregion

		private int _getDistrictShapeRequestCount = 0;
        public int getDistrictShapeRequestCount
        {
            get { return _getDistrictShapeRequestCount; }
            set { if (_getDistrictShapeRequestCount != value) { _getDistrictShapeRequestCount = value; NotifyPropertyChanged("getDistrictShapeRequestCount"); } }
        }



        public static bool IsError(string callingMethod, Exception error, object serviceMethodResult, string serviceErrorMessage)
        {
            // error in WCF service call
            if (Log.HandleException(error))
            {
                return true;
            }

            // unknown error in the service method
            if (serviceMethodResult == null)
            {
                MessageBox.Show(callingMethod + " : " + error.Message.ToString());
            }
            else
            {
                // caught error in the service method
                if (Log.HandleServerError(callingMethod + " : ", serviceErrorMessage))
                {
                    return true;
                }
            }

            return false;
        }
    }
}
